#define _WIN32_WINNT 0x0500

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <iostream>
#include <WinConfig.h>

#if defined(_DEBUG) && defined(__VISUAL_STUDIO)
  #include<crtdbg.h>
#endif

//using namespace std;

	int close(int) { return 0; }
	int write(int,void const *,int) { return 0; }
	int lseek(int,int,int) { return 0; }
	int open(char const *,int,...) { return 0; }
	struct tm * localtime_r(long const *,struct tm const *) { return 0; }
	int time(long *) { return 0; }
	
	time_t mktime(struct tm const *) { return 0; }
	struct tm * gmtime_r(long const *,struct tm const *) { return 0; }

	void sleep(int) {}

extern "C" {
	
#if defined(__VISUAL_STUDIO)
	int isnan(const int &) { return 0; }
	int gettimeofday(struct timeval *,struct timezone *) { return 0; }
	int signbit(int x) { return x<0; }
#endif

	long int gethostid() { return 0; }
	void syslog(int,char*,...) {}
	int munmap(void *,unsigned int) { return 0; }
	void * mmap(void *,unsigned int,int,int,int,long) { return 0; }
	int map(int,int) { return 0; }
	int msync(char*,...) { return 0; }

	int pthread_mutex_unlock(int) { return 0; }
	int pthread_mutex_lock(int) { return 0; }

	int rint(double a) { return (int)a; }
	int finite(double a) { return _finite(a); }
	int sigaction(int, sigaction*, sigaction*) { return 1; }
	void sigemptyset(int *a) { *a=0; }
	int fchmod(int,int) { return (int)true;}
	int ftruncate(int a,int) { return a; }
	int mkstemp(char a) { return (int)a;}
	int fcntl(int,int,...) { return 1; }
	int ieee_handler(char*,char*,void*()) { return 0; }
	int sysconf(int a) { return a; }
	void getrlimit(int,rlimit*) {}
	void setrlimit(int,rlimit*) {}
	int srandom(int) { return 0; }
	int getwd(char) { return 0; }
	char* ctime_r(long*,char*) { return 0; }

	unsigned long mb(long*,unsigned long) { return 0; }
	unsigned long MZ[] = { 1L, 2L, 4L, 8L, 16L, 32L, 64L, 128L, 256L, 512L, 1024L, 2048L, 4096L, 8192L, 16384L, 32768L };
	int S_ISDIR(unsigned short) { return 1; }
	unsigned long *mz(void) { return 0; }
	unsigned long mc(void) { return 0; }
	void times(tms*) {}

	double atanh(const double&) { return 0; }
	double acosh(const double&) { return 0; }
	double asinh(const double&) { return 0; }
	int iszero(const int &) { return 0; }
	int random() { return rand(); }
	int microsleep(int) { return 0; }

	int pclose(FILE*) { return 0; }
	FILE* popen(const char*,const char*) { return 0; }
	char* bnstring(char *arg0,...) { return NULL; }

	void openlog(char*,int,int) {}
	void closelog() {};
	passwd* getpwuid(int) { return 0; }
	int getuid() { return 0; }

	void checkmem() 
	{
#if defined(_DEBUG) && defined(__VISUAL_STUDIO)
	  int check = _CrtCheckMemory();
	  if (!check) { 
	  	__asm int 3; 
	  }

	  HANDLE heap = GetProcessHeap();
	  check = HeapValidate(heap,0,NULL);
	  if (!check) { 
	  	__asm int 3; 
	  }
#endif
	}

	void checkpointer(void* a) {
#if defined(_DEBUG) && defined(__VISUAL_STUDIO)
	  int check = _CrtIsValidHeapPointer(a);
	  if (!check) { 
	  	__asm int 3; 
	  }
#endif
	}
		
	void mf_malloc(long *p) 
    { 
	  checkpointer(p);
	  checkmem();
	  return free(p);
	}

	long *ma_malloc(unsigned long a) {
		long* b = (long*) malloc(a); 
		checkpointer(b);
		return b;
	}

	void* dlsym(int,char*) { return 0; }
	void dlclose(int) {}
	char* dlerror() { return (char*)""; }
	void* dlopen(char*,int) { return 0; }

int win32select(int , fd_set*,int,int,int)
{
	/*
	HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
	FlushConsoleInputBuffer(handle);

  CONSOLE_FONT_INFO consInfo;
  GetCurrentConsoleFont(handle,1,&consInfo);

	SetConsoleMode(handle,ENABLE_ECHO_INPUT|ENABLE_LINE_INPUT|ENABLE_PROCESSED_INPUT);
	cout << "Waiting for input" << endl;
	WaitForSingleObject(handle,INFINITE);
	cout << "Got input" << endl;
	*/
	return 0;
}

char * tzname[] = { (char*)"GMT", (char*)"BST" };
};
